class ProductManager:
    def __init__(self):
        self.products = {}
        self.category_products = {}
        self.brand_products = {}

    def add_product(self, product):
        self.products[product.product_id] = product

        # 按分类索引
        if product.category not in self.category_products:
            self.category_products[product.category] = []
        self.category_products[product.category].append(product)

        # 按品牌索引
        if product.brand not in self.brand_products:
            self.brand_products[product.brand] = []
        self.brand_products[product.brand].append(product)

    def get_product(self, product_id):
        return self.products.get(product_id)

    def get_products_by_category(self, category):
        return self.category_products.get(category, [])

    def get_products_by_brand(self, brand):
        return self.brand_products.get(brand, [])

    def get_all_products(self):
        return list(self.products.values())